home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
LANG
/
C
/
LIB
/
UNIXLIB37B
/
!UnixLib37
/
src
/
stdio
/
c
/
setbuf
< prev
next >
Wrap
Text File
|
1996-11-09
|
2KB
|
74 lines
/****************************************************************************
*
* $Source: /unixb/home/unixlib/source/unixlib37/src/stdio/c/RCS/setbuf,v $
* $Date: 1996/11/06 22:01:42 $
* $Revision: 1.2 $
* $State: Rel $
* $Author: unixlib $
*
* $Log: setbuf,v $
* Revision 1.2 1996/11/06 22:01:42 unixlib
* Yet more changes by NB, PB and SC.
*
* Revision 1.1 1996/04/19 21:32:42 simon
* Initial revision
*
***************************************************************************/
static const char rcs_id[] = "$Id: setbuf,v 1.2 1996/11/06 22:01:42 unixlib Rel $";
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
__STDIOLIB__
/* If buf is null, this makes stream unbuffered.
Otherwise it makes stream fully buffered using buf
as the buffer (of size size). */
void
setbuffer (FILE *stream, char *buf, size_t size)
{
setvbuf (stream, buf, (buf) ? _IOFBF : _IONBF, size);
}
/* Make stream be line buffered, and allocate the buffer. */
void
setlinebuf (FILE *stream)
{
setvbuf (stream, NULL, _IOLBF, 0);
}
void
setbuf (register FILE * f, char *buf)
{
setvbuf (f, buf, (buf) ? _IOFBF : _IONBF, BUFSIZ);
}
int
setvbuf (register FILE * f, register char *buf, register int flag,
register size_t bufsiz)
{
if (f->flag & _IOREAD)
{
if (f->i_base)
return (-1);
f->i_ptr = f->i_base = (unsigned char *) buf;
}
else if (f->flag & _IOWRITE)
{
if (f->o_base)
return (-1);
f->o_ptr = f->o_base = (unsigned char *) buf;
}
else
return (-1);
f->bufsiz = (!bufsiz) ? 1 : bufsiz;
f->flag = (f->flag & (~_IOBF)) | (flag & _IOBF);
return (0);
}